﻿namespace Cmn.Cls
{
    using System;
    using System.Text;
    using System.Web.Mail;

    public class Email
    {
        private string _Body;
        private string _FromEmail;
        private string _SmtpPassword;
        private string _SmtpServer;
        private string _SmtpUserName;
        private string _Subject;

        public bool Send(string toEmail)
        {
            try
            {
                MailMessage message = new MailMessage {
                    From = this._FromEmail,
                    To = toEmail,
                    BodyFormat = MailFormat.Html,
                    BodyEncoding = Encoding.Default,
                    Subject = this._Subject,
                    Body = this._Body
                };
                message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1");
                message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", this._SmtpUserName);
                message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", this._SmtpPassword);
                SmtpMail.SmtpServer = this._SmtpServer;
                SmtpMail.Send(message);
                return true;
            }
            catch
            {
                return false;
            }
        }

        public string Body
        {
            set
            {
                this._Body = value;
            }
        }

        public string FromEmail
        {
            set
            {
                this._FromEmail = value;
            }
        }

        public string SmtpPassword
        {
            set
            {
                this._SmtpPassword = value;
            }
        }

        public string SmtpServer
        {
            set
            {
                this._SmtpServer = value;
            }
        }

        public string SmtpUserName
        {
            set
            {
                this._SmtpUserName = value;
            }
        }

        public string Subject
        {
            set
            {
                this._Subject = value;
            }
        }
    }
}

